package edu.xhu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.Toast;

public class EduTeacherIndexActivity extends Activity{
	
	private TextView title;
	private XhuApplication application;
	private Button mBtnBack;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.teacher_index);
		initView();
	}
	
	private void initView()
	{
		title 			= (TextView) findViewById(R.id.title);
		application		= (XhuApplication) getApplication();
		mBtnBack		= (Button) findViewById(R.id.button_back);
		mBtnBack.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
		
		
		if (application.isLogin()){
			title.setText("欢迎您：" + application.getUserName());
		}else {
			if (application.getUserName() != null && application.getRole() == XhuApplication.TEACHER)
				title.setText("欢迎您：" + application.getUserName() + " - 未登录");
			Toast.makeText(EduTeacherIndexActivity.this, R.string.no_login_model, Toast.LENGTH_LONG).show();
		}
		
		LayoutInflater inflater = LayoutInflater.from(this);
		LinearLayout container = (LinearLayout) findViewById(R.id.container);
	
		//第一行
    	LinearLayout layout = new LinearLayout(EduTeacherIndexActivity.this);
		layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		layout.setOrientation(LinearLayout.VERTICAL);
		
		View view = inflater.inflate(R.layout.main_item, null);
		ImageView img = (ImageView) view.findViewById(R.id.img);
		img.setImageResource(R.drawable.sg1);
		TextView textView = (TextView) view.findViewById(R.id.control_name);
		textView.setText("课表查询");
		view.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(EduTeacherIndexActivity.this, EduSystemTimeTable.class);
				startActivity(intent);
			}
		});

		layout.addView(view);
		
		view = inflater.inflate(R.layout.main_item, null);
		img = (ImageView) view.findViewById(R.id.img);
		img.setImageResource(R.drawable.g1_1);
		textView = (TextView) view.findViewById(R.id.control_name);
		textView.setText("名单查询");
		view.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(EduTeacherIndexActivity.this, EduTeaNameList.class);
				startActivity(intent);
			}
		});
		
		layout.addView(view);
		container.addView(layout);
	} // initView
}
